package net.qhzw.vip.qiyu.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.qhzw.vip.qiyu.entity.GuaranteeSite;
import net.qhzw.vip.qiyu.model.BigDataInfo;
import net.qhzw.vip.qiyu.model.BigDataInfoFask;
import net.qhzw.vip.qiyu.model.BigDataInfoFaskModel;
import net.qhzw.vip.qiyu.result.JsonResult;
import net.qhzw.vip.qiyu.service.GuaranteeSiteService;
import net.qhzw.vip.qiyu.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("bigData")
@Api(tags = "大屏数据获取")
public class BigDataInfoController {

    @Autowired
    private GuaranteeSiteService guaranteeSiteService;


    @ApiOperation(value = "查询各站点换车退车租车量")
    @GetMapping("/getSiteVehicles/{id}")
    public JsonResult getCarinfoSite(@PathVariable String id) {
        List<BigDataInfo> list = guaranteeSiteService.getCarStatistics(id);
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "当日充值金额")
    @GetMapping("/getTheSiteTurnover")
    public JsonResult getTheSiteTurnover() {
            List<BigDataInfo> list = guaranteeSiteService.getTheSiteTurnover();
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "商城经销商前15销售额排名图")
    @GetMapping("/getMallDealersBef")
    public JsonResult getMallDealersBef() {
        List<BigDataInfo> list = guaranteeSiteService.getMallshoping();
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "商城商品月销售总量")
    @GetMapping("/getMallDealersBefTotal")
    public JsonResult getMallDealersBefTotal() {
        List<BigDataInfo> list = guaranteeSiteService.getMallshopingTotal();
        return JsonResult.ok(list);
    }
    @ApiOperation(value = "商城经销商商品总销售额")
    @GetMapping("/getMallTotalMoney")
    public JsonResult getMallTotalMoney() {
        String mallTotalMoney = guaranteeSiteService.getMallTotalMoney();
        return JsonResult.ok(mallTotalMoney);
    }
    @ApiOperation(value = "在租用户总")
    @GetMapping("/getInRentTheUser")
    public JsonResult getInRentTheUser() {
        String mallTotalMoney = guaranteeSiteService.getInRentTheUser();

        return JsonResult.ok(mallTotalMoney);
    }
    @ApiOperation(value = "在租各商铺")
    @GetMapping("/getNowunder")
    public JsonResult getNowunder() {
        List<BigDataInfo> nowunder = guaranteeSiteService.getNowunder();
        return JsonResult.ok(nowunder);
    }


    @ApiOperation(value = "奇遇收入指标统计(总和)")
    @GetMapping("getIncmIndicatorsCount")
    public JsonResult getIncmIndIncome() {
        //BigDecimal incmIdxStat = guaranteeSiteService.getIncmIdxStat();
        List<BigDataInfo> list = guaranteeSiteService.getTheSiteTurnover();
        BigDecimal sumMoney ;
        if (list!=null) {
            for (BigDataInfo bigDataInfo : list) {
                sumMoney =  new BigDecimal(bigDataInfo.getTentalRev()).add(new BigDecimal(bigDataInfo.getXferTurnover())).add(new BigDecimal(bigDataInfo.getTheCarSales()));
                bigDataInfo.setSumMoney(sumMoney);
            }

        }
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "骑遇小遇 租车业务 商城业务 维修业务综合统计")
    @GetMapping("carRentMallRepairCount")
    public JsonResult getCarRentMallRepairCount() {
        Map<String, Integer> result = guaranteeSiteService.getComprehensiveStatistics();
        return JsonResult.ok(result);
    }

    @ApiOperation(value = "维修救援 维修师傅指标统计")
    @GetMapping("/getMaintStatisticsCar")
    public JsonResult getMaintStatisticsCar() {
        List<BigDataInfo> list = guaranteeSiteService.getMaintIdxStatistics();
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "商户租车电池业务指标统计")
    @GetMapping("/getBusCarRentalBusStatistics")
    public JsonResult getBusCarRentalBusStatistics() {
        List<BigDataInfo> list = guaranteeSiteService.getBusCarRentalBusStatistics();
        return JsonResult.ok(list);
    }


    @ApiOperation(value = "担保公司维度统计")
    @GetMapping("/getGuarCoDimensionStatistics")
    public JsonResult getGuarCoDimensionStatistics() {
        List<BigDataInfo> list = guaranteeSiteService.getGuarCoDimensionStatistics();
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "一键增加数据量")
    @GetMapping("/getAddData/{isFaker}")
    public JsonResult getAddData(@PathVariable String isFaker) {
     boolean update  = guaranteeSiteService.updateIsFaker(isFaker);
        if (update) {
            return JsonResult.ok();
        }
        return JsonResult.fail();

    }

    @ApiOperation(value = "查询故障恢复率及禁仓回复率")
    @GetMapping("/getBarcount")
    public JsonResult getBarCount() {
        List<BigDataInfo> list = guaranteeSiteService.getBarCount();
        return JsonResult.ok(list);
    }

}